from typing import *
from leetcode.editor.common.node import *


# leetcode submit region begin(Prohibit modification and deletion)
class Solution:
    def getAverages(self, nums: List[int], k: int) -> List[int]:
        # 滑动窗口慢慢划
        n = len(nums)
        ans = [-1] * n
        voler = 0  # 窗口中的和
        # 定长的长度
        l = 2 * k + 1
        for right, item in enumerate(nums):
            voler += item

            left = right - l + 1
            if left >= 0:
                ans[right - k] = voler // l
                voler -= nums[left]
        return ans
# leetcode submit region end(Prohibit modification and deletion)


if __name__ == '__main__':
    solution = Solution()
    print(solution.getAverages([7,4,3,9,1,8,5,2,6], 3))
    # your test code here